<template>
	<view class="mywallet">
		<view class="mywallet_quanbu">
			<view class="mywallet_dibu">

			</view>
			<view class="mywallet_shang">
				<view class="mywallet_shang_top">
					<image class="img" src="../../static/img/d.png"></image>
					<view class="mywallet_shang_top_a">
						<view style="    padding: 20rpx 0rpx;">
							<view class="mywallet_shang_top_b">
								<view class="mywallet_shang_top_c">
									<view class="text1">总资产(元)</view>
									<view class="text2">{{mywalletobj.amount}}</view>
								</view>
								<image class="imag" src="../../static/img/q.png"></image>
							</view>
							<view class="mywallet_shang_top_c">
								<view class="mywallet_shang_top_d">
									<text class="text3">可提现金额(元)</text>
									<text class="text4">未结算金额(元)</text>
								</view>
								<view class="mywallet_shang_top_e">
									<text class="text5">{{mywalletobj.usableAmount}}</text>
									<text class="text6">{{mywalletobj.frozenAmount}}</text>
								</view>
							</view>
						</view>

					</view>
				</view>

				<view class="mywallet_shang_mingxi">
					<view class="mywallet_shang_mingxi_a">
						<view class="mywallet_shang_mingxi_shang">
							<text class="text1">消费明细</text>
							<text class="text2"></text>
						</view>
						<!-- <view class="example-body">
							<uni-datetime-picker v-model="range" type="daterange" @change="maskClick" />
						</view> -->


					</view>
					<view class="mywallet_box">
						<view class="mywallet_shang_mingxi_shang_right">
							<text class="text1" :class="item.id==ID?'box':''" v-for="item in shourulist" :key="item.id"
								@click="tab(item.id)">{{item.name}}</text>
						</view>
					</view>

					
					<scroll-view class="scroll-view" @scrolltolower="scrollData" style="height:76%;" scroll-y="true">
						<view v-if="isshow" style="text-align: center;">
							<image src="../../static/iconShow/noOrder.png"></image>
						</view>
						<view class="mywallet_shang_mingxi_xia" v-for="(item,index) in orederList" :key="item.id"
							@click="details(item.billType,item.id)">
							<view class="mywallet_shang_mingxi_xia_a">

								<view class="mywallet_shang_mingxi_xia_b">
									<image class="img" src="../../static/img/dd.png"></image>
									<view class="mywallet_shang_mingxi_xia_c">
										<text class="text1">{{item.changeTypeName}}</text>
										<text class="text2">{{item.linkId}} </text>

									</view>
									<text class="text3">{{item.createTime}}</text>
								</view>
								<view class="jiaqian" v-if="item.pm==1">+{{item.number}}</view>
								<view class="jiaqian" v-if="item.pm==0" :style="item.pm==0?'color:#FF8F1F':''">
									-{{item.number}}</view>
							</view>
						</view>

					</scroll-view>
				</view>
				<view class="tixian" @click="withdraw">
					提现
				</view>

			</view>

		</view>




	</view>
</template>

<script>
	import homeServices from '../../service/homeService'
	// import uDatetimePicker from '../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/util.js'
	export default {
		// components: {
		// 	uDatetimePicker
		// },
		data() {
			return {
				ID: -1,
				total: 0,
				page: 1,
				orederList: [],
				loadingType: 0,
				timer: null,
				mywalletobj: {},
				isloading: false,
				range: [],
				shourulist: [{
						id: 1,
						name: '收入'
					},
					{
						id: 0,
						name: '支出'
					},
				],
				isshow: false
				


			}
		},
		watch: {
			range(newval) {
				console.log('范围选:', this.range);
				this.range = newval
				// console.log('范围选:', this.range);
			},

		},

		methods: {
			// async maskClick(e) {
			// 	let arr = e
			// 	let params = {
			// 		createTime: arr
			// 	}
			// 	let res = await homeServices.maskClick(params)
			// 	let list = res.data.records
			// 	if (this.pagenum === 1) {
			// 		this.goodsList = list;
			// 	} else {
			// 		this.goodsList = [...this.goodsList, ...list];
			// 	}
			// 	this.total = res.data.total
			// },
			async accountinfo() {
				let res = await homeServices.accountinfo()
				this.mywalletobj = res.data

			},
			withdraw() {
				
				uni.navigateTo({
					url: `../../pagesA/withdraw/withdraw?withdraw=${this.mywalletobj.usableAmount}`
				})
			},
			details(type, id) {
				console.log('@@@');
				if (type == 'masseuse') {
					uni.navigateTo({
						url: '../../pagesA/details/details?id=' + id
					})
				}
				if (type == 'goods') {
					uni.navigateTo({
						url: '../../pagesA/feededuction/feededuction?id=' + id
					})
				}


			},
			async tab(id) {
				this.ID = id
				this.loadingType = 0
				this.orederList = []
				this.page = 1
				
				this.getorderlist()

			},
			async getorderlist() {
				if (this.loadingType !== 0) { //loadingType!=0;直接返回

					return false;

				}
				this.loadingType = 1;
				if (this.ID == -1) {
					var params = {
						page: this.page,
						limit: this.limit,
					}
				} else {
					var params = {
						page: this.page,
						limit: this.limit,
						pm: this.ID
					}
				}

				let res = await homeServices.maskClick(params)
				
				if (res.status == 200) {

					this.page++
					console.log(this.page)
					if (res.data.records.length < 1) {
						this.loadingType = 2;
						return
					}
					this.orederList = this.orederList.concat(res.data.records)
					console.log(this.orederList)
					// if(this.page==res.data.current){
					// 	console.log(this.page);
					// 	console.log(res.data.current);
					// 	uni.showToast({
					// 		title: '到底了',
					// 		icon: 'none',
					// 		duration: 2000, 
					// 	})
					// }
					this.loadingType = 0;
				}
				if(this.orederList.length !==null){
					this.isshow=false
				}else{
					this.isshow=true
				}
			},
			
			scrollData() {
				if (this.timer != null) {
					clearTimeout(this.timer)
				}
				this.timer = setTimeout(() => {
					this.getorderlist()
				}, 500)
			}


		},
		onShow() {
			this.page = 1
			
		},
		
		onLoad() {
			this.getorderlist()
			this.accountinfo()
		}

	}
</script>

<style lang="scss" scoped>
	@import '@/static/sass/mywallet.scss'
</style>
